﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RentHouse.DTO;
using RentHouse.IService;
using RentHouse.Service.Entities;
using RentHouse.Common;
namespace RentHouse.Service
{
    public class CommunityService : ICommunityService
    {
        public List<CommuityDTO> GetCommuities(long regionId)
        {
            using (var db=new RentHouseContext())
            {
                var bs = new BaseService<T_Communities>(db);
                var query = PredicateExtensions.True<T_Communities>();
                if (regionId>0)
                {
                    query = query.And(e => e.RegionId == regionId);
                }
                var list = bs.GetList(query).Select(e=>new CommuityDTO() { 
                BuiltYear=e.BuiltYear==null? 0:(int)e.BuiltYear ,
                Id=e.Id,
                Location=e.Location,
                Name=e.Name,
                RegionId=e.RegionId,
                Traffic=e.Traffic
                }).ToList();
                return list;
            }
        }
    }
}
